
#include "../mpmdComm.hpp"
#include "mpi.h"
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
using namespace EXTREAM;
int main(int argc, char **argv) {

  int my_rank, num_proc;
  MPI_Init(&argc, &argv);

  MpmdComm::getObjPtr()->init(MPI_COMM_WORLD);
  // POFile::initWithMultiAPP(MpmdComm::getObjPtr()->localComm(),
  //                          MpmdComm::getObjPtr()->appId(), true);

  const int local_comm_size = MpmdComm::getObjPtr()->localCommSize();
  const int remote_comm_size = MpmdComm::getObjPtr()->remoteCommSize();
  const int local_rank = MpmdComm::getObjPtr()->rankInLocal();
  //   vector<int> send_data(remote_comm_size * 2, local_rank);

  vector<int> recv_data(remote_comm_size, -1);
  vector<MPI_Request> reqs(remote_comm_size);
  vector<MPI_Status> stas(remote_comm_size);
  // 只接收不发送
  if (local_rank == 1) {
    for (int i = 0; i < remote_comm_size; ++i) {
      MPI_Irecv(recv_data.data() + i, 1, MPI_INT, i, 1,
                MpmdComm::getObjPtr()->interComm(), reqs.data() + i);
    }
    MPI_Waitall(reqs.size(), reqs.data(), stas.data());
  }
  if (local_rank == 1) {
    for (int i = 0; i < recv_data.size(); ++i) {
      cout << recv_data[i] << "  ";
    }
    cout << endl;
  }
  MpmdComm::release();
  MPI_Finalize();
  return 0;
}